package org.zhadoop.stream.cql.semanticanalyzer.parser.context;

import java.util.List;

import org.zhadoop.stream.cql.DriverContext;
import org.zhadoop.stream.cql.exception.CQLException;
import org.zhadoop.stream.cql.exception.SemanticAnalyzerException;
import org.zhadoop.stream.cql.hooks.SemanticAnalyzeHook;
import org.zhadoop.stream.cql.semanticanalyzer.FromClauseAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.SemanticAnalyzer;
import org.zhadoop.stream.cql.semanticanalyzer.parsecontextwalker.ParseContextWalker;
import org.zhadoop.stream.cql.tasks.Task;

/**
 * from 子语句解析内容
 * 
 * @author zwd
 *
 */
public class FromClauseContext extends ParseContext {

	private JoinSourceContext sourceContext;
	
	private CombineConditionContext combine;

	@Override
	public String toString() {
		 StringBuilder sb = new StringBuilder();
	        sb.append("FROM ");
	        sb.append(sourceContext.toString());
	        if (combine != null){
	            sb.append(" " + combine.toString());
	        }
	        return sb.toString();
	}
	
	
	public JoinSourceContext getSourceContext() {
		return sourceContext;
	}

	public void setSourceContext(JoinSourceContext sourceContext) {
		this.sourceContext = sourceContext;
	}
	
	public CombineConditionContext getCombine() {
		return combine;
	}

	public void setCombine(CombineConditionContext combine) {
		this.combine = combine;
	}


	@Override
	public Task createTask(DriverContext driverContext, List<SemanticAnalyzeHook> analyzeHooks) throws CQLException {
		return null;
	}

	@Override
	public SemanticAnalyzer createAnalyzer() throws SemanticAnalyzerException {
		return new FromClauseAnalyzer(this);
	}


	@Override
	protected void walkChild(ParseContextWalker walker) {
		walkExpression(walker,sourceContext);
		walkExpression(walker,combine);
	}

}
